package util.designpattern.strategyPattern;

import java.util.HashMap;
import java.util.Map;

public class PromotionStrategyFactory {
    private static Map<String, Strategy> PROMOTION_STARTEGY_MAP = new HashMap<String, Strategy>();
    static {
        PROMOTION_STARTEGY_MAP.put(PromotionKey.COIPON,new ConcreteStrategyA());
        PROMOTION_STARTEGY_MAP.put(PromotionKey.CASHBACK,new ConcreteStrategyB());
        PROMOTION_STARTEGY_MAP.put(PromotionKey.GROUPBUY,new ConcreteStrategyC());
    }
    private static final Strategy STRATEGY = new ConcreteStrategyC();
    private PromotionStrategyFactory(){}

    /**
     * 根据指定的键获取指定的对象
     * @param promotionKey
     * @return
     */
    public static Strategy getStrategy(String promotionKey){
        Strategy strategy = PROMOTION_STARTEGY_MAP.get(promotionKey);
        
        return strategy == null ? STRATEGY : strategy;
    }

    /**
     * 常量定义
     */
    private interface PromotionKey{
        String COIPON = "COUPON";
        String CASHBACK = "CASHBACK";
        String GROUPBUY = "GFOUPBY";
    }
}
